package lab03.test12;

import java.sql.*;

public class Test {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;
        String str="select * from t_users";
        String string="select * from t_users where username='admin'";
        String string1="select * from t_users where username='admin'and password='123456'";
        String string2="select * from t_users where register_datetime>10000000";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC&characterEncoding=utf-8","root","123456");
            statement=connection.createStatement();
            resultSet=statement.executeQuery(string);
            while (resultSet.next()){
                System.out.println(resultSet.getInt(1));
                System.out.println(resultSet.getString(2));
                System.out.println(resultSet.getString(3));
                System.out.println(resultSet.getLong(4));
                System.out.println();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally {
            try {
                connection.close();
                statement.close();
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
